const path = require('path')
const fs = require('fs-extra')

const pathToDatabase = path.join(__dirname, '../../database.json')

const getDatabase = exports.getDatabase = async () => {
    try {
        const database = await fs.readJson(pathToDatabase);
        return {
            currentYear: new Date().getFullYear(),
            ...database,
        }
    } catch (err) {
        console.log(err)
    }
}

exports.setDatabase = async (jsonData) => {
    try {
        const database = await getDatabase();
        await fs.writeJson(pathToDatabase, jsonData)
    } catch (err) {
        console.log(err)
    }
}
